Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rp2040 freertos #1993

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

rppicomidi
Copy link
Contributor

@rppicomidi rppicomidi commented Mar 29, 2023

Describe the PR
This draft pull request shows a possible way to implement FreeRTOS support for RP2040.
To use FreeRTOS with RP2040, you must install the FreeRTOS-Kernel source in a way that family.cmake can find it. Easiest place to put it is

    ${PICO_SDK_PATH}/../FreeRTOS-Kernel

Make sure to use the smp branch. That is:

    cd ${PICO_SDK_PATH}/../FreeRTOS-Kernel
    git checkout smp

In your project's CMakeFiles.txt, use libraries

    tinyusb_board_freertos, tinyusb_device_freertos,
    tinyusb_host_freertos

instead of the libraries without the '_freertos' suffix

At some point, the FreeRTOS-Kernel smp branch will merge with the main branch. Hopefully, the large number of compiler warnings will be cleared by then.

Additional context
See discussion #1951.

Edit: I meant to make this a draft pull request. Anyone know how to change it?

To use FreeRTOS with RP2040, you must install the
FreeRTOS-Kernel source in a way that family.cmake
can find it. Easiest place to put it is
${PICO_SDK_PATH}/../FreeRTOS-Kernel

Make sure to use the smp branch. That is:
cd ${PICO_SDK_PATH}/../FreeRTOS-Kernel
git checkout smp

In your project's CMakeFiles.txt, use libraries
tinyusb_board_freertos, tinyusb_device_freertos,
and tinyusb_host_freertos instead of the libraries
without the '_freertos' suffix

At some point, the FreeRTOS-Kernel smp branch will
merge with the main branch. Hopefully, the large
number of compiler warnings will be cleared by then.
@rppicomidi rppicomidi marked this pull request as draft March 30, 2023 03:02
I spelled continue() wrong. If the FreeRTOS-Kernel directory
was not installed, this would break the build.
For backward compatibility with projects that set
TINYUSB_OPT_OS in the CMakeLists.txt to
OPT_OS_FREERTOS to create libraries without the
_freertos suffix, only add the contents of
TINYUSB_OPT_OS to the supported OS list.
endif()
set(PROJ_SUFFIX "")
foreach(SUPPORTED_OS IN LISTS SUPPORTED_OS_LIST)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you copy this here when you have FreeRTOS_Kernel_import.cmake too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because FreeRTOS_Kernel_import.cmake has a fatal error message lines 47-49.

if (NOT FREERTOS_KERNEL_PATH)
    message(FATAL_ERROR "FreeRTOS location was not specified. Please set FREERTOS_KERNEL_PATH.")
endif()

As I understand it, we do not want pico-sdk to fail to build if FreeRTOS-Kernel is not installed.

@rppicomidi
Copy link
Contributor Author

@hathach The build pre-comit is failing. I do not understand why file FreeRTOS_Kernel_import.cmake requires a blank line at the end of the file. The file pico_sdk_import.cmake does not have one.

@hathach
Copy link
Owner

hathach commented Apr 5, 2023

@hathach The build pre-comit is failing. I do not understand why file FreeRTOS_Kernel_import.cmake requires a blank line at the end of the file. The file pico_sdk_import.cmake does not have one.

You need to leave an empty line at the end of the file to make ci check happy. On my editor the pico_sdk_import.cmake does have one.

image

@hathach
Copy link
Owner

hathach commented Apr 5, 2023

I am making some chagnes to the cmake as well to better support both esp32 and rp2040 as well as others later on. https://github.com/hathach/tinyusb/tree/cmake . I am currently busy, but once I get that merged first, I will hep to sync up this branch

@hathach
Copy link
Owner

hathach commented Apr 21, 2023

still haven't decided which is best way to do this, but I may follow the approach using by FreeRTOS-kernel https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/CMakeLists.txt which also requires an external file config I.e adding CMakelists.txt that define tinyusb as a lib but requires an target that expose tusb_config.h in the include path. Pico-sdk can define both no os and freertos config, and one that does not speciy the freertos config in the library link will use the no os one. Let me know what you think about this approach.

@rppicomidi
Copy link
Contributor Author

@hathach That works for a single, stand-alone project but I think it does not work if you build the project from the pico-examples project? The top level CMakeLists.txt contains include(pico_sdk_import.cmake) which includes tinyusb build which prevents using the proper CMake variables later.

@hathach
Copy link
Owner

hathach commented May 4, 2023

yeah, you are right, I think I will need to add _freertos to the library in the cmakelists.txt target. Another way to solve this is don't inline osal_ function, that allows to link to osal implementation later. However, I don't feel to go that approach since it requires too much changes for existing projects that use tinyusb. _freertos suffix target then, I am also slowly adding cmake target for tinyusb. Will continue to do that and make changes as needed regarding this PR.

@kilograham
Copy link
Collaborator

fyi, i have been crazy busy, and will be for a bit longer, so apologies for not getting to this yet.

@hathach
Copy link
Owner

hathach commented May 9, 2023

fyi, i have been crazy busy, and will be for a bit longer, so apologies for not getting to this yet.

No problems, we are all busy, I am actually working to add cmake build to tinyusb repo as well (for src/ and all other mcu families). Also latest freertos-kernel is adding support for CMake as well https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/CMakeLists.txt

@hathach
Copy link
Owner

hathach commented Jun 27, 2023

Thank you for making PR, after doing quite a bit of works to support cmake for other mcus, I am getting better with it. I agree that adding tinyusb_device_freertos and tinyusb_host_freertos is best approach. Though I think we should do it in pico-sdk, I also think the freertos-kernel lib should be also added there rather than within tinyusb. That will help pico user by just simply link with freertos-kernel and or tinyusb_device_freertos. Check out my PR to pico-sdk here raspberrypi/pico-sdk#1438 . @kilograham @rppicomidi would you mind review/comment and move our discussion to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

3 participants